from django.db import models

# Create your models here.
class Student(models.Model):
    SEX_CHOICES=[
        (0,'女'),
        (1,'男')
    ]
    name=models.CharField(max_length=20,verbose_name='姓名')
    age=models.SmallIntegerField('年龄',null=True,blank=True)
    sex=models.SmallIntegerField('性别',choices=SEX_CHOICES)
    c_time=models.DateTimeField('创建时间',auto_now_add=True)
    u_time=models.DateTimeField('修改时间',auto_now=True)
    is_delete=models.BooleanField('逻辑删除',default=False)

    #关联字段
    classes=models.ForeignKey('Classes',on_delete=models.SET_NULL,null=True,verbose_name='班级')


    # 重写delete方法，实现逻辑删除
    def delete(self, using=None, keep_parents=False):
        self.is_delete=True
        self.save()


class Classes(models.Model):
    name=models.CharField(max_length=20,verbose_name='班级名称',help_text='班级名称')
    num=models.CharField('班期',max_length=20,help_text='班期')
    c_time=models.DateTimeField('创建时间',auto_now_add=True,help_text='创建时间')
    u_time=models.DateTimeField('修改时间',auto_now=True,help_text='修改时间')
    is_delete=models.BooleanField('逻辑删除',default=False,help_text='逻辑删除')


    # 重写delete方法，实现逻辑删除
    def delete(self, using=None, keep_parents=False):
        self.is_delete=True
        self.save()

    def __str__(self):
        return f'{self.name}-{self.num}'